import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  BeforeInsert,
  CreateDateColumn,
  Generated,
  OneToOne,
  JoinColumn,
  ManyToOne,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm'
import { User } from '../../user/entities/user.entity'
import { Commit } from 'src/commit/entities/commit.entity'
@Entity()
export class Post {
  @PrimaryGeneratedColumn('uuid')
  id: string

  @Column({
    type: 'varchar',
    comment: '标题',
    nullable: false,
    length: 255,
  })
  title: string
  @Column({ type: 'text' })
  content!: string
  @Column({
    type: 'varchar',
    comment: '描述',
    nullable: true,
    length: 255,
  })
  discuss: string

  @Column({
    type: 'varchar',
    comment: '圈子',
    nullable: true,
    length: 255,
  })
  topic: string
  @Column({
    type: 'simple-array',
    comment: '图片数组',
    nullable: true,
    // length: 255,
  })
  imgArray: string[]
  @Column({
    type: 'varchar',
    comment: '地点',
    nullable: true,
    length: 255,
  })
  address: string

  @Column({ type: 'int', default: 0 })
  eye!: number
  @Column({ type: 'int', default: 0 })
  thumb!: number

  @ManyToOne(() => User, (user) => user.posts)
  @JoinColumn()
  user: User

  @OneToMany(()=>Commit,(commit)=>commit.post)
  commits: Commit[]


  @CreateDateColumn({ type: 'timestamp', update: false, comment: '创建时间' })
  create_time: Date
  @UpdateDateColumn({ type: 'timestamp', update: true, comment: '更新时间' })
  update_time: Date
}
